#coding: utf-8
class HomeController < ApplicationController
  before_filter :load_sidebar_data
  def index
    @cate1_posts = Post.find(:all,
      :joins => :category,
      :conditions => ["categories.id = ? or categories.parent_id = ? ",1,1],
      :limit => 6
    )
    
    @cate9_posts = Post.find(:all,
      :joins => :category,
      :conditions => ["categories.id = ? or categories.parent_id = ? ",9,9],
      :limit => 6
    )
    
    @cate15_posts = Post.find(:all,
      :joins => :category,
      :conditions => ["categories.id = ? or categories.parent_id = ? ",15,15],
      :limit => 6
    )
    
    @cate20_posts = Post.find(:all,
      :joins => :category,
      :conditions => ["categories.id = ? or categories.parent_id = ? ",20,20],
      :limit => 6
    )
  end
  
  def search
    q = "%#{params[:keyword]}%"
    @posts = Post.where("title like ?",q).paginate(:page => params[:page], :per_page =>10)
  end
  
  def posts
    @post = Post.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @post }
    end
  end
  
end
